package PaChong;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

/**
 * @description:
 * @author: 张德长 dechang.zhang@ucarinc.com
 * @date: 14:29:28 2018/10/31
 * @version:2.0
 */
public class Html {
    public static String getHtml(String url) throws IOException {
        //创建client实例
        HttpClient client = HttpClients.createDefault();
        //创建httpget实例
        /*RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(50000).setConnectionRequestTimeout(50000)
                .setSocketTimeout(50000).build();*/

        HttpGet httpGet = new HttpGet(url);
        //httpGet.setConfig(requestConfig);
        HttpResponse response = null;
        response = client.execute(httpGet);
        //返回获取实体
        HttpEntity entity = response.getEntity();
        //获取网页内容，指定编码
        String web = EntityUtils.toString(entity, "UTF-8");
        return web;
    }
}
